import vue from "vue"
import vuex from 'vuex'
vue.use(vuex)

import chat from './modules/chat.js';
// import user	from './modules/user.js';
// import statistics	from './modules/statistics.js';

const store = new vuex.Store({
	modules: {
		chat, // 即时通讯
	},
	state: { //存放状态
		"userInfo": uni.getStorageSync('userInfo') || '',
		"config": uni.getStorageSync('config') || '',
		"token": uni.getStorageSync('token') || '',
		"myAdd": uni.getStorageSync('myAdd') || '',
	},
	mutations: {
		setData(state, data) {
			uni.setStorage({
				key: data[0],
				data: data[1]
			})
			state[data[0]] = data[1]
		},
		setUser(state, data) {
			uni.setStorage({
				key: "userInfo",
				data: data
			})
			state.userInfo = data
		},
		setConfig(state, data) {
			uni.setStorage({
				key: "config",
				data: data
			})
			state.config = data
		},
		setToken(state, data) {
			uni.setStorage({
				key: "token",
				data: data
			})
			state.token = data
		},
	}
})

export default store
